#
# scrap.py -- rendering debis
# 
# author: Tom "Knio" Flanagan
#         knio@h4xn3t.net
#         theknio@gmail.com
#         irc.freenode.net - Knio - #python #pygame #py
#
# this file released under Public Domain
#

from constants import *
import object

class Scrap(object.Object):
    sprites = {}
    def init(self):
        Scrap.image = pygame.image.load('images/scrap.bmp').convert()
        Scrap.image.set_colorkey((0,0,0), RLEACCEL)

    def get_sprite(self, size, angle):
        angle = int(angle)
        if not (size,angle) in self.sprites:
            n = self.image.get_size()
            n = (int(n[0]*size/15.) or 1, int(n[1]*size/15.) or 1)
            sprite = pygame.transform.scale(self.image, n)
            sprite = pygame.transform.rotate(sprite, angle)
            self.sprites[(size,angle)] = sprite
        return self.sprites[(size,angle)]        


    def tick(self):
        self.view.dirty.append(pygame.Rect(self.rect))
        self.sprite = self.get_sprite(self.model.size, self.model.f/PI*180-90)
        self.rect = self.sprite.get_rect()
        self.rect.centerx = self.view.offset+self.model.x
        self.rect.centery = self.view.offset-self.model.y
        self.view.dirty.append(pygame.Rect(self.rect))
        self.render()

    def render(self):
        self.view.screen.blit(self.sprite, self.rect)        
        
